home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-05-22 | 3.0 KB | 118 lines | [TEXT/ttxt] |
- \ Grep - not a true grep. It does not search for full regular expressions
- \ but only a string of symbols in the set of terminals.
- \ 10/15/84 rw
- \ 1/18/85 cbd eliminated coded searches in favor of string
- \ 2/15/86 cdn restrict file names to print only on match
- \ 9/02/86 cdn Added case sensitivity option
- \ 9/16/86 cdn Added text highlighting: bold line #, underline match, --more--
- \ 9/20/86 cdn Added tab expansion
- \ 12/29/90 rfl modified for sarray path
- \ 5/19/92 rfl now exits more gracefully, and doesn't search yerk folder unless specified
- \
- \ "grflgs" bits:
- \ 0 - case sensitive
- \ 1 - egrep patterns (not yet implemented)
- \ 2 - pause for screen full
-
- :Module grepMod
-
- // vol
- forget dir
-
- String gpattern
- String linBuf
- String target
- 0 value curLin#
- 0 value #lines
-
- \ pause output if option being used
- : more
- grflgs 04 and
- IF curLin# ?lines 3 - >=
- IF 1 tFace ." --More--" 0 tFace key drop CR
- 0 -> curLin#
- THEN
- THEN ;
-
- false value getOut
- : pause? false -> getOut
- ?terminal IF (key) drop cr .pause (key) cr 0 -> out 32 >
- IF true ELSE false THEN
- ELSE false
- THEN -> getOut ;
-
- \ ( -- ) ( VARS: linecount, mybuf ) n.b. also assumes gpattern set
- : SearchFile { \ line# .name? -- }
- 0 -> line# 1 -> .name?
- BEGIN pause?
- topFile 80 readLine: linBuf not getOut not and
- WHILE
- 1 ++> line#
- target =: linBuf start: target
- grflgs 01 and 0= IF uc: target 2drop THEN
- get: gpattern indexOf: target
- IF .name?
- IF more cr getName: topFile type ." :" cr 2 ++> curLin#
- 0 -> .name?
- THEN
- more
- 1 tFace \ bold
- line# 3 .r ." ->" start: linBuf
- 0 tFace \ plain
- dup substr: linBuf type
- 4 tFace \ underline
- dup moveTo: linBuf
- size: gpattern dup substr: linBuf type
- + dup moveTo: linBuf
- 0 tFace \ plain
- size: linBuf swap - substr: linBuf type cr 1 ++> curLin#
- THEN
- REPEAT
- line# ++> #lines
- ;
-
- \ GREP - Will search through all text
- \ files for the string specified in object gpattern; printing out the
- \ file name, line number and line for all occurrences of the string it
- \ locates.
- : (grep) { addr len \ gcurs dirid -- } false -> getOut
- watchcurs 0 -> #lines 0 -> curLin#
- curs -> gcurs -curs \ Preserve cursor status
- new: loadFile new: gpattern new: target
- addr len str255 -base count put: gPattern
- ." Searching for: " print: gPattern CR
- grflgs 01 and IF ." -Case sensitive-" CR
- ELSE uc: gPattern 2drop THEN
- new: linBuf
- HFS? IF limit: path ELSE 1 THEN 0
- DO path IF i at: path name: fFcb
- ELSE fFcb clrfcb
- THEN
- i at: path swap drop 0>
- IF Filecount 1+ 1
- DO i getidxfile
- IF pad count " System" s= not
- IF pad count name: topFile
- getdirid: ffcb setdirid: topfile
- openReadOnly: topFile ?error 132
- GetFileInfo: topFile drop
- GetType: topFile txType =
- IF searchfile THEN
- close: topFile drop
- THEN
- THEN
- getOut IF Leave THEN
- LOOP
- getOut IF Leave THEN
- THEN
- LOOP
- gcurs -> curs \ Restore cursor status
- remove: loadFile release: gpattern release: target
- release: linBuf
- cr #lines . ." lines searched." cr arrowcurs
- ;
-
- : grep word" count (grep) ;
-
- ;Module
-